package bb.lanxing.adapter.sport;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import bb.lanxing.fragment.sport.SportRecordListFragment;
import bb.lanxing.model.database.Workout;

public class SportRecordAdapter extends FragmentPagerAdapter {
    private List<String> tabLayoutList = new ArrayList<>();
    private List<Fragment> fragmentList = new ArrayList<>();

    public SportRecordAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return tabLayoutList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tabLayoutList.get(position);
    }

    public void updateData(List<String> monthList, List<List<Workout>> workoutsList) {
        tabLayoutList = monthList;
        fragmentList.clear();
        for (List<Workout> workouts : workoutsList) {
            fragmentList.add(new SportRecordListFragment(workouts));
        }
        notifyDataSetChanged();
    }
}